package com.dlc.shop.systemtest.api.amount;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dlc.shop.common.util.PageParam;
import com.dlc.shop.distribution.common.dto.AchievementDataDto;
import com.dlc.shop.distribution.common.dto.DistributionOrderDto;
import com.dlc.shop.distribution.common.model.DistributionUser;
import com.dlc.shop.distribution.common.vo.DistributionUserInfoVO;
import com.dlc.shop.systemtest.constants.Constant;
import com.dlc.shop.systemtest.util.HttpUtil;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author: zsm
 * @date: 2023/2/28 9:10
 */
public class DistributionUserApi {

    /**
     * 查看分销中心信息
     * @return
     */
    public static AchievementDataDto info(){
        String url = Constant.API_URL + "/p/distribution/user/info";
        return HttpUtil.get(url,AchievementDataDto.class);
    }

    /**
     * 分页查看分销员佣金明细
     * @param page
     * @return
     */
    public static void getDistributionOrderDtosByDistributionUserId(PageParam<DistributionOrderDto> page){
        String url = Constant.API_URL + "/p/distribution/user/distributionUserOrders";
        HttpUtil.get(url);
    }


    /**
     * 获取好友接口
     * @param userType 类型 1 我的用户， 2 我的好友
     * @return
     */
     public static List<DistributionUserInfoVO> subordinateUserPage(@RequestParam(value = "userType") Integer userType){
        String url = Constant.API_URL + "/p/distribution/user/subordinateUser"+ "?userType=" + userType;
         List list = HttpUtil.get(url, List.class);
         return  JSON.parseArray(JSONObject.toJSONString(list), DistributionUserInfoVO.class);
    }

    /**
     * 分销员信息
     * @return
     */
    public static AchievementDataDto isDistributionUser(){
        String url = Constant.API_URL + "/p/distribution/user/distributionUserInfo";
        return HttpUtil.get(url,AchievementDataDto.class);
    }

    /**
     * 根据用户id获取分销员信息
     * @param userId
     * @return
     */
    public static DistributionUser getDistributionUserInfoByUserId(@PathVariable("userId") String userId){
        String url = Constant.PLATFORM_URL + "/distribution/distributionUser/getInfo/" + userId;
        return HttpUtil.get(url,DistributionUser.class);
    }

    /**
     * 根据分销员id获取分销员信息
     * @param distributionUserId
     * @return
     */
    public static DistributionUser getDistributionUserInfoByDistributionUserId(@PathVariable("userId") Long distributionUserId){
        String url = Constant.PLATFORM_URL + "/distribution/distributionUser/info/" + distributionUserId;
        return HttpUtil.get(url,DistributionUser.class);
    }
}
